package com.live.activity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.live.common.Constant;
import com.live.common.LiveCommon;
import com.live.task.LiveMessage;

public class LiveMessageActivity extends LiveBaseActivity {

	private Bundle bundle;
	private TextView content;
	private TextView charSum;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.live_message);

		/* 获取Intent中的Bundle对象 */
		bundle = this.getIntent().getExtras();

		content = (TextView) findViewById(R.id.content);
		charSum = (TextView) findViewById(R.id.charSum);

		// 设置头部信息
		LiveCommon.setHead(context, (LinearLayout) findViewById(R.id.liveHead), R.string.topic_message,
				R.string.msg_btn);

		// 设置头部按钮（留言）
		Button sendMsgBtn = (Button) findViewById(R.id.headFuncBtn);
		sendMsgBtn.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// 当有内容时
				if (content.getText().toString().trim().length() > 0) {
					bundle.putString("content", content.getText().toString());
					LiveMessage task = new LiveMessage(context, null, null, null, Constant.ACTION_INSERT, null, null);
					task.execute(bundle);
				}
			}
		});

		content.addTextChangedListener(new TextWatcher() {
			private CharSequence temp;

			@Override
			public void beforeTextChanged(CharSequence s, int arg1, int arg2, int arg3) {
				temp = s;
			}

			@Override
			public void onTextChanged(CharSequence s, int arg1, int arg2, int arg3) {
				charSum.setText(temp.length() + "/140");
			}

			@Override
			public void afterTextChanged(Editable s) {
			}
		});

	}
}